Public Class ACDataGridViewHelpTextBox
   Inherits ACHelpTextBox
   Implements IDataGridViewEditingControl

   Private DataGridViewControl As DataGridView
   Private ValueIsChanged As Boolean = False
   Private RowIndexNum As Integer
   Public Shadows Event ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)


   Public Sub New()
      Me.Text = ""
   End Sub

   Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle) Implements System.Windows.Forms.IDataGridViewEditingControl.ApplyCellStyleToEditingControl
      MyBase.Font = dataGridViewCellStyle.Font
      MyBase.ForeColor = dataGridViewCellStyle.ForeColor
      MyBase.BackColor = dataGridViewCellStyle.BackColor
   End Sub

   Public Property EditingControlDataGridView() As System.Windows.Forms.DataGridView Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlDataGridView
      Get
         Return DataGridViewControl
      End Get
      Set(ByVal value As System.Windows.Forms.DataGridView)
         DataGridViewControl = value
      End Set
   End Property

   Public Property EditingControlFormattedValue() As Object Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlFormattedValue
      Get
         Return Me.Text
      End Get
      Set(ByVal value As Object)
         Me.Text = value.ToString
      End Set
   End Property

   Public Property EditingControlRowIndex() As Integer Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlRowIndex
      Get
         Return RowIndexNum
      End Get
      Set(ByVal value As Integer)
         RowIndexNum = value
      End Set
   End Property

   Public Property EditingControlValueChanged() As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlValueChanged
      Get
         Return ValueIsChanged
      End Get
      Set(ByVal value As Boolean)
         ValueIsChanged = value
      End Set
   End Property

   Public Function EditingControlWantsInputKey(ByVal keyData As System.Windows.Forms.Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlWantsInputKey
      If keyData = Keys.Escape Then
         Return False
      Else
         Return True
      End If
   End Function

   Public ReadOnly Property EditingPanelCursor() As System.Windows.Forms.Cursor Implements System.Windows.Forms.IDataGridViewEditingControl.EditingPanelCursor
      Get
         Return MyBase.Cursor
      End Get
   End Property

   Public Function GetEditingControlFormattedValue(ByVal context As System.Windows.Forms.DataGridViewDataErrorContexts) As Object Implements System.Windows.Forms.IDataGridViewEditingControl.GetEditingControlFormattedValue
      Return Me.Text
   End Function

   Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) Implements System.Windows.Forms.IDataGridViewEditingControl.PrepareEditingControlForEdit

   End Sub

   Public ReadOnly Property RepositionEditingControlOnValueChange() As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.RepositionEditingControlOnValueChange
      Get
         Return False
      End Get
   End Property

   Private Sub btnAyuda_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ButtonClick
      RaiseEvent ButtonClick(sender, e)
   End Sub

   Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
      ValueIsChanged = True
      Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
      MyBase.OnTextChanged(e)
   End Sub

End Class

Public Class ACDataGridViewHelpTextBoxColumn
   Inherits DataGridViewColumn

   Public Sub New()
      MyBase.New()
      Dim HelpTextBoxCell As New ACDataGridViewHelpTextBoxCell
      MyBase.CellTemplate = HelpTextBoxCell
   End Sub

   Public Overrides Property CellTemplate() As System.Windows.Forms.DataGridViewCell
      Get
         Return MyBase.CellTemplate
      End Get
      Set(ByVal value As System.Windows.Forms.DataGridViewCell)
         If (value IsNot Nothing) AndAlso Not value.GetType().IsAssignableFrom(GetType(ACDataGridViewHelpTextBoxCell)) Then
            Throw New InvalidCastException("Debe ser un ACDataGridViewHelpTextBoxCell")
         End If
         MyBase.CellTemplate = value
      End Set
   End Property

End Class

Public Class ACDataGridViewHelpTextBoxCell
   Inherits DataGridViewTextBoxCell

   Public Sub New()
      MyBase.New()
      Me.Style.Format = ""
   End Sub

   Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle)
      MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
      Dim ctl As ACDataGridViewHelpTextBox = CType(DataGridView.EditingControl, ACDataGridViewHelpTextBox)
      ctl.Text = CType(IIf(Me.Value Is DBNull.Value, "", Me.Value), String)
   End Sub

   Public Overrides ReadOnly Property EditType() As System.Type
      Get
         Return GetType(ACDataGridViewHelpTextBox)
      End Get
   End Property

   Public Overrides ReadOnly Property ValueType() As System.Type
      Get
         Return GetType(String)
      End Get
   End Property

   Public Overrides ReadOnly Property DefaultNewRowValue() As Object
      Get
         Return ""
      End Get
   End Property

End Class





